package a_producer;

public class Consumer extends Thread {
    @Override
    public void run() {
        while (true) {
            synchronized (Bread.lock) {
                if (Bread.count == 0){
                    break;
                }else {
                    if(Bread.flag){
                        System.out.println("正在消费面包");
                        Bread.count--;
                        //需要唤醒生产者线程
                        Bread.lock.notify();
                    }else {
                        //没有面包
                        //进入等待状态
                        try {
                            Bread.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
}